<?php

require_once "tfsbox_abstract_view.class.php";

class TFsBOXLoginView extends TFsBOXAbstractView
	{
		function __construct()
		{
		}

		function renderEmailSent()
			{
				echo "<div class=\"tfsbox_container\">\n";
				echo "<h2>E-mail Sent</h2>\n";
				echo "<p>An e-mail has been sent with the information you have requested.</p>\n";
				echo "</div>\n";
			}

		function renderForgotPasswordForm()
			{
				echo "<form id=\"tfsbox_login_form\" action=\"". $_SERVER['REQUEST_URI'] ."\" method=\"post\">\n";
				echo "<table cellspacing=\"3\" cellpadding=\"3\" style=\"border: 0; width: 100%;\">\n";
				echo "<tr>\n";
				echo "<th colspan=\"2\">Reset Password</th>";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>E-mail:</b></td>\n";
				echo "<td><input class=\"tfsbox_textfield\" type=\"text\" name=\"tfsbox_email\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td></td>\n";
				echo "<td style=\"text-align: center;\">\n";
				echo "<input type=\"reset\" value=\"Clear\"/>\n";
				echo "<input type=\"submit\" value=\"Submit\"/>\n";
				echo "</td>\n";
				echo "</tr>\n";
				echo "</table>\n";
				echo "</form>\n";
			}

		function renderForgotUsernameForm()
			{
				echo "<form id=\"tfsbox_login_form\" action=\"". $_SERVER['REQUEST_URI'] ."\" method=\"post\">\n";
				echo "<table cellspacing=\"3\" cellpadding=\"3\" style=\"border: 0; width: 100%;\">\n";
				echo "<tr>\n";
				echo "<th colspan=\"2\">Forgot Username</th>";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>E-mail:</b></td>\n";
				echo "<td><input class=\"tfsbox_textfield\" type=\"text\" name=\"tfsbox_email\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td></td>\n";
				echo "<td style=\"text-align: center;\">\n";
				echo "<input type=\"reset\" value=\"Clear\"/>\n";
				echo "<input type=\"submit\" value=\"Submit\"/>\n";
				echo "</td>\n";
				echo "</tr>\n";
				echo "</table>\n";
				echo "</form>\n";
			}

		function renderLoginForm()
			{
				$usr = (isset($_POST['tfsbox_username'])) ? $_POST['tfsbox_username'] : "";
				echo "<form id=\"tfsbox_login_form\" action=\"". $_SERVER['REQUEST_URI'] ."\" method=\"post\">\n";
				echo "<table cellspacing=\"3\" cellpadding=\"3\" style=\"border: 0; width: 100%;\">\n";
				echo "<tr>\n";
				echo "<th colspan=\"2\">TFsBOX Log-in</th>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Username:</b></td>\n";
				echo "<td><input class=\"tfsbox_textfield\" name=\"tfsbox_username\" type=\"text\" value=\"". $usr ."\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td><b>Password:</b></td>\n";
				echo "<td><input class=\"tfsbox_textfield\" name=\"tfsbox_password\" type=\"password\"/></td>\n";
				echo "</tr>\n";
				echo "<tr>\n";
				echo "<td></td>\n";
				echo "<td style=\"text-align: center;\">\n";
				echo "<input type=\"reset\" value=\"Clear\"/>\n";
				echo "<input type=\"submit\" value=\"Log In\"/>\n";
				echo "</td>\n";
				echo "</tr>\n";
				echo "</table>\n";
				echo "</form>\n";
			}

		function renderMenuBar()
			{
				$forgot_password = ($_SERVER['PATH_INFO'] == "/tfsbox/login/forgot_username") ? " id=\"active\"" : "";
				$register = ($_SERVER['PATH_INFO'] == "/tfsbox/login/register") ? " id=\"active\"" : "";
				$reset_password = ($_SERVER['PATH_INFO'] == "/tfsbox/login/reset_password") ? " id=\"active\"" : "";

				echo "<div id=\"tfsbox_panel_menubar\">\n";
				TFsBOXAbstractView::renderButton("Register",
												 $_SERVER['SCRIPT_NAME'] ."/tfsbox/login/register",
												 TFsBOXSession::urlRoot() ."/images/icons/add-user.png",
												 $register);
				TFsBOXAbstractView::renderButton("Forgot Username",
												 $_SERVER['SCRIPT_NAME'] ."/tfsbox/login/forgot_username",
												 TFsBOXSession::urlRoot() ."/images/icons/user-properties.png",
												 $forgot_password);
				TFsBOXAbstractView::renderButton("Reset Password",
												 $_SERVER['SCRIPT_NAME'] ."/tfsbox/login/reset_password",
												 TFsBOXSession::urlRoot() ."/images/icons/clear-history.png",
												 $reset_password);
				if (!$forgot_password && !$register && !$reset_password)
					TFsBOXAbstractView::renderButton("Log-in Issues",
													 "javascript: show_msg_dialog('".
													 addslashes('<ul><li>'
															   .'<b>I have been magically logged out though I know I was logged in:</b><p> '
															   .'If you have a dynamic IP address and it changes during the session, '
															   .'or you decide to switch browsers, you\'ll have to log in again. '
															   .'The session will otherwise last only 14 days; you can clear your cookies and try again, but if you feel something more serious is going on, you may reset your password.</p>'
															   .'</li><li>'
															   .'<b>I keep being informed that either my username or password is incorrect:</b><p> '
															   .'To have your username e-mailed to you, click on \'Forgot Username\'. '
															   .'To reset your password, \'Reset Password\'. '
															   .'Do note that multiple failed log-in attempts will lock your account.</p>'
															   .'</li></ul>')
													 ."');",
													 TFsBOXSession::urlRoot() ."/images/icons/system-help.png");
				else
					TFsBOXAbstractView::renderButton("Log In",
													 $_SERVER['SCRIPT_NAME'] ."/tfsbox/login",
													 TFsBOXSession::urlRoot() ."/images/icons/login.png");
				echo "</div>\n";
			}

		function renderRegisterForm()
			{
				echo "<form id=\"tfsbox_login_form\" action=\"". $_SERVER['REQUEST_URI'] ."\" method=\"post\">\n";
				echo "<table cellspacing=\"3\" cellpadding=\"3\" style=\"border: 0; width: 100%;\">\n";
				echo "<tr>";
				echo "<th colspan=\"2\">TFsBOX Registration</th>";
				echo "</tr>";
				echo "<tr>";
				echo "<td><b>Username:</b></td>";
				echo "<td><input type=\"text\" name=\"tfsbox_username\" class=\"tfsbox_textfield\" value=\"". $_POST['tfsbox_username'] ."\"/></td>";
				echo "</tr>";
				echo "<tr>";
				echo "<td><b>Password:</b></td>";
				echo "<td><input type=\"text\" name=\"tfsbox_password\" class=\"tfsbox_textfield\"/></td>";
				echo "</tr>";
				echo "<tr>";
				echo "<td><b>E-mail:</b></td>";
				echo "<td><input type=\"text\" name=\"tfsbox_email\" class=\"tfsbox_textfield\" value=\"". $_POST['tfsbox_email'] ."\"/></td>";
				echo "</tr>";
				echo "<tr>";
				echo "<td><b>Site:</b></td>";
				echo "<td><input type=\"text\" name=\"tfsbox_site\" class=\"tfsbox_textfield\" title=\"Optional\"/></td>";
				echo "</tr>";
				echo "<tr>";
				echo "<td colspan=\"2\" style=\"text-align: right;\">";
				echo "<input type=\"submit\" value=\"Register\"/>";
				echo "</td>";
				echo "</tr>";
				echo "</table>";
				echo "</form>\n";
			}

		function renderRegistrationCompletePage()
			{
				echo "<div class=\"tfsbox_container\">\n";
				echo "<h2>Registration Complete</h2>\n";
				echo "<p>Thank you for taking the time to register. ";
				$settings = TFsBOX::$Database->settings();
				if ($settings["verification_method"] == "email")
					echo "Account verification is required, and an e-mail has been sent to the address provided. Please follow the instructions therein.";
				else if ($settings["verification_method"] == "cpanel")
					echo "Account verification is required but is left to the administrator. Please wait till you have been verified.";
				echo "</p>\n";
				echo "</div>\n";
			}
	}

?>
